﻿Imports Training.Common

Partial Public Class DeleteGroup
    Inherits System.Web.UI.Page
    Public gName As String ' group name
    Dim gid As Integer

    ''' <summary>
    ''' Page Load event, check for querystring data and assign to variables
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' check for querystring data
        If IsNothing(Request.QueryString("gid")) Or IsNothing(Request.QueryString("nm")) Then
            Response.Redirect("Groups.aspx")
        Else
            gid = Request.QueryString("gid")
            gName = Request.QueryString("nm")
        End If
    End Sub

    ''' <summary>
    ''' Cancel button click event. User opts NOT to delete group. Redirect
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("Groups.aspx")
    End Sub

    ''' <summary>
    ''' Delete button click event. Order of events follows:
    ''' Identify all users in group
    ''' Delete all quiz/module data for users
    ''' Delete logins for users
    ''' Delete users
    ''' Delete modules data for group
    ''' Delete login for group
    ''' Delete group
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>redirect back to Groups.aspx after completion</remarks>
    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        ' delete all user data
        DeleteGroupUsersAndData(gid)

        ' delete group module data
        DeleteGroupModules(gid)

        ' delete login for group
        DeleteGroupLogin(gid)

        ' delete group record
        DeleteGroupByID(gid)

        ' redirect
        Response.Redirect("Groups.aspx")
    End Sub
End Class